<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>粘性(含糖)复测实验结果记录单</title>
    <link rel="stylesheet" href="./css/all.min.css">
    <script src="static-data.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(-45deg, #667eea, #764ba2, #f093fb, #f5576c);
            background-size: 400% 400%;
            animation: gradientShift 15s ease infinite;
            min-height: 100vh;
            color: #333;
            line-height: 1.6;
        }

        @keyframes gradientShift {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 30px;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            padding: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
        }

        .back-btn {
            background: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 10px 20px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .back-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateY(-2px);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .container {
                padding: 15px;
            }

            .header {
                flex-direction: column;
                gap: 15px;
                text-align: center;
            }

            .header h1 {
                font-size: 24px;
            }

            .barcode-input-row {
                flex-direction: column;
                align-items: stretch;
            }

            .barcode-input {
                min-width: auto;
            }

            .barcode-btn {
                width: 100%;
            }

            .notification-container {
                top: 10px;
                right: 10px;
                left: 10px;
                max-width: none;
            }

            .notification {
                padding: 14px 16px;
            }
        }

        .header h1 {
            color: white;
            font-size: 28px;
            font-weight: 600;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }

        /* 条形码输入区域样式 */
        .barcode-input-section {
            background: white;
            border-radius: 15px;
            padding: 25px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            animation: fadeInUp 0.6s ease forwards;
        }

        .barcode-input-row {
            display: flex;
            align-items: center;
            gap: 15px;
            flex-wrap: wrap;
        }

        .barcode-label {
            font-weight: 600;
            color: #2c3e50;
            font-size: 16px;
            min-width: 120px;
        }

        .barcode-input {
            flex: 1;
            min-width: 300px;
            padding: 12px 16px;
            border: 2px solid #e1e8ed;
            border-radius: 10px;
            font-size: 14px;
            transition: all 0.3s ease;
            background: #f8f9fa;
        }

        .barcode-input:focus {
            outline: none;
            border-color: #667eea;
            background: white;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }

        .barcode-btn {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 10px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 600;
            transition: all 0.3s ease;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            min-width: 100px;
            justify-content: center;
        }

        .barcode-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
        }

        .barcode-btn:active {
            transform: translateY(0);
        }

        /* 加载动画 */
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }

        .barcode-btn:hover {
            animation: pulse 0.6s ease-in-out;
        }

        .form-container {
            background: white;
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            animation: fadeInUp 0.6s ease forwards;
            animation-delay: 0.2s;
            width: 100%;
        }

        /* 保持a4-page类的原有样式不变 */
        .a4-page {
            font-family: SimSun, serif;
            background: white;
            padding: 20px;
        }
        
        .a4-page .title {
            text-align: center;
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 30px;
        }
        
        .a4-page table {
            border-collapse: collapse;
            width: 100%;
            max-width: 1600px;
            max-height: 900px;
            margin: 0 auto;
        }
        
        .a4-page td {
            border: 1px solid black;
            padding: 8px;
            text-align: center;
            vertical-align: middle;
            height: 40px;
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .attachment-label {
            position: absolute;
            top: 20px;
            left: 20px;
            font-weight: bold;
            font-size: 16px;
            color: #2c3e50;
        }

        .info-section {
            margin-bottom: 25px;
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
        }

        .info-group {
            display: flex;
            align-items: center;
        }

        .label {
            font-weight: bold;
            margin-right: 10px;
            min-width: 80px;
        }

        .input-field {
            border: 1px solid #000;
            padding: 5px 10px;
            font-size: 14px;
            min-width: 120px;
            background: #fff;
        }

        .table-container {
            margin-top: 30px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            border: 1px solid #000;
        }

        th, td {
            border: 1px solid #000;
            padding: 8px;
            text-align: center;
            font-size: 14px;
        }

        th {
            background: #f0f0f0;
            font-weight: bold;
        }

        .table-input {
            border: none;
            width: 100%;
            text-align: center;
            background: transparent;
            font-size: 14px;
        }

        .scannable {
            background: #ffffcc;
            border: 2px solid #ffcc00;
        }

        .scannable:focus {
            border: 2px solid #ff6600;
            background: '#fff8dc';
        }

        .footer {
            margin-top: 30px;
            text-align: center;
            font-size: 12px;
            color: #666;
        }

        .detection-indicators {
            display: flex;
            gap: 20px;
            margin-bottom: 20px;
        }

        .indicator-group {
            display: flex;
            align-items: center;
        }

        .checkbox-group {
            display: flex;
            gap: 15px;
        }

        .checkbox-item {
            display: flex;
            align-items: center;
        }

        .checkbox-item input[type="checkbox"] {
            margin-right: 5px;
        }

        /* 通知样式 */
        .notification-container {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1000;
            max-width: 350px;
        }

        .notification {
            background: white;
            border-radius: 12px;
            padding: 16px 20px;
            margin-bottom: 10px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
            border-left: 4px solid;
            position: relative;
            animation: slideInRight 0.3s ease;
            display: flex;
            align-items: flex-start;
            gap: 12px;
        }

        .notification.success {
            border-left-color: #4ecdc4;
        }

        .notification.error {
            border-left-color: #ff6b6b;
        }

        .notification.info {
            border-left-color: #667eea;
        }

        .notification-icon {
            width: 24px;
            height: 24px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            color: white;
            flex-shrink: 0;
            margin-top: 2px;
        }

        .notification-icon.success {
            background: linear-gradient(135deg, #4ecdc4, #44a08d);
        }

        .notification-icon.error {
            background: linear-gradient(135deg, #ff6b6b, #ee5a24);
        }

        .notification-icon.info {
            background: linear-gradient(135deg, #667eea, #764ba2);
        }

        .notification-content {
            flex: 1;
            min-width: 0;
        }

        .notification-title {
            font-size: 14px;
            font-weight: 600;
            color: #2c3e50;
            margin: 0 0 4px 0;
            line-height: 1.3;
        }

        .notification-message {
            font-size: 13px;
            color: #666;
            margin: 0;
            line-height: 1.4;
        }

        .notification-close {
            background: none;
            border: none;
            font-size: 16px;
            color: #999;
            cursor: pointer;
            padding: 2px;
            border-radius: 50%;
            transition: all 0.3s ease;
            flex-shrink: 0;
            margin-top: 2px;
        }

        .notification-close:hover {
            background: #f8f9fa;
            color: #333;
        }

        .notification-progress {
            position: absolute;
            bottom: 0;
            left: 0;
            height: 3px;
            background: rgba(0, 0, 0, 0.1);
            border-radius: 0 0 12px 12px;
            animation: progressShrink 3s linear;
        }

        .notification.success .notification-progress {
            background: linear-gradient(90deg, #4ecdc4, #44a08d);
        }

        .notification.error .notification-progress {
            background: linear-gradient(90deg, #ff6b6b, #ee5a24);
        }

        .notification.info .notification-progress {
            background: linear-gradient(90deg, #667eea, #764ba2);
        }

        @keyframes slideInRight {
            from {
                opacity: 0;
                transform: translateX(100%);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        @keyframes slideOutRight {
            from {
                opacity: 1;
                transform: translateX(0);
            }
            to {
                opacity: 0;
                transform: translateX(100%);
            }
        }

        @keyframes progressShrink {
            from { width: 100%; }
            to { width: 0%; }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <button onclick="window.location.href='index.html'" class="back-btn">
                <i class="fas fa-home"></i> 返回首页
            </button>
            <h1><i class="fas fa-microscope"></i> 粘性(含糖)复测实验结果记录单</h1>
            <div style="width: 100px;"></div>
        </div>

        <!-- 条形码输入区域 -->
        <div class="barcode-input-section">
            <div class="barcode-input-row">
                <span class="barcode-label">寄送机构:</span>
                <input type="text" id="sendingInstitution" class="barcode-input" placeholder="请输入机构名称">
                <span class="barcode-label">机构代码:</span>
                <input type="text" id="institutionCode" class="barcode-input scannable" placeholder="请输入代码" maxlength="4">
            </div>
            <div class="barcode-input-row">
                <span class="barcode-label">样品来源:</span>
                <input type="text" id="sampleSource" class="barcode-input scannable" placeholder="请输入样品来源">
                <span class="barcode-label">组合号码:</span>
                <input type="text" id="combinationNumber" class="barcode-input scannable" placeholder="请输入组合号码">
            </div>
            <div class="barcode-input-row">
                <span class="barcode-label">检测日期:</span>
                <input type="date" id="testDate" class="barcode-input">
                <button class="barcode-btn" onclick="scanBarcode('sendingInstitution')">扫描机构</button>
                <button class="barcode-btn" onclick="scanBarcode('institutionCode')">扫描代码</button>
            </div>
        </div>

        <div class="form-container">
            <div class="a4-page">
                <div class="title">粘性(含糖)复测实验结果记录单</div>
                <table>
                    <tr>
                        <td colspan="2">寄送机构</td>
                        <td colspan="4"><span id="sendingInstitutionDisplay"></span></td>
                        <td colspan="2">机构代码</td>
                        <td colspan="4"><span id="institutionCodeDisplay"></span></td>
                    </tr>
                    <tr>
                        <td colspan="2">样品来源</td>
                        <td colspan="4"><span id="sampleSourceDisplay"></span></td>
                        <td colspan="2">组合号码</td>
                        <td colspan="4"><span id="combinationNumberDisplay"></span></td>
                    </tr>
                    <tr>
                        <td colspan="2">检测日期</td>
                        <td colspan="10"><span id="testDateDisplay"></span></td>
                    </tr>
                    <tr>
                        <td rowspan="6">复测样品</td>
                        <td>样品1</td>
                        <td colspan="2">复测实验方法</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="实验方法"></td>
                        <td colspan="2">测试机构代号</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="机构代号"></td>
                    </tr>
                    <tr>
                        <td>样品2</td>
                        <td colspan="2">复测实验方法</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="实验方法"></td>
                        <td colspan="2">测试机构代号</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="机构代号"></td>
                    </tr>
                    <tr>
                        <td>样品3</td>
                        <td colspan="2">复测实验方法</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="实验方法"></td>
                        <td colspan="2">测试机构代号</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="机构代号"></td>
                    </tr>
                    <tr>
                        <td>样品4</td>
                        <td colspan="2">复测实验方法</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="实验方法"></td>
                        <td colspan="2">测试机构代号</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="机构代号"></td>
                    </tr>
                    <tr>
                        <td>样品5</td>
                        <td colspan="2">复测实验方法</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="实验方法"></td>
                        <td colspan="2">测试机构代号</td>
                        <td colspan="2"><input type="text" class="table-input scannable" placeholder="机构代号"></td>
                    </tr>
                    <tr>
                        <td colspan="11">备注</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>

    <!-- 通知容器 -->
    <div class="notification-container" id="notificationContainer"></div>

    <script>
        // 扫描枪输入处理
        let currentFocusElement = null;

        // 为所有可扫描元素添加点击事件
        document.addEventListener('click', function(e) {
            if (e.target.classList.contains('scannable') || 
                e.target.closest('.scannable') || 
                e.target.tagName === 'INPUT' && e.target.classList.contains('scannable')) {
                
                // 移除之前的高亮
                document.querySelectorAll('.scannable').forEach(el => {
                    el.style.border = '2px solid #ffcc00';
                    el.style.background = '#ffffcc';
                });
                
                // 高亮当前元素
                const targetElement = e.target.classList.contains('scannable') ? e.target : e.target.closest('.scannable');
                if (targetElement) {
                    currentFocusElement = targetElement;
                    targetElement.style.border = '2px solid #ff6600';
                    targetElement.style.background = '#fff8dc';
                    targetElement.focus();
                }
            }
        });

        document.addEventListener('focusin', function(e) {
            if (e.target.classList.contains('scannable')) {
                currentFocusElement = e.target;
                e.target.style.border = '2px solid #ff6600';
                e.target.style.background = '#fff8dc';
            }
        });

        document.addEventListener('focusout', function(e) {
            if (e.target.classList.contains('scannable')) {
                e.target.style.border = '2px solid #ffcc00';
                e.target.style.background = '#ffffcc';
            }
        });

        // 键盘输入处理（模拟扫描枪）
        document.addEventListener('keydown', function(e) {
            if (e.key === 'Enter' && currentFocusElement) {
                e.preventDefault();
                processScannedData(currentFocusElement.value);
                currentFocusElement.blur();
            }
        });

        // 通知功能
        function showNotification(options = {}) {
            const {
                title = '提示',
                message = '',
                type = 'info', // success, error, info
                duration = 3000 // 自动消失时间，毫秒
            } = options;

            const container = document.getElementById('notificationContainer');
            
            // 创建通知元素
            const notification = document.createElement('div');
            notification.className = `notification ${type}`;
            
            // 图标映射
            const iconMap = {
                success: 'fas fa-check-circle',
                error: 'fas fa-exclamation-circle',
                info: 'fas fa-info-circle'
            };

            // 设置通知内容
            notification.innerHTML = `
                <div class="notification-icon ${type}">
                    <i class="${iconMap[type]}"></i>
                </div>
                <div class="notification-content">
                    <div class="notification-title">${title}</div>
                    <div class="notification-message">${message}</div>
                </div>
                <button class="notification-close" onclick="removeNotification(this.parentElement)">
                    <i class="fas fa-times"></i>
                </button>
                <div class="notification-progress"></div>
            `;

            // 添加到容器
            container.appendChild(notification);

            // 自动移除
            setTimeout(() => {
                removeNotification(notification);
            }, duration);

            return notification;
        }

        function removeNotification(notification) {
            if (notification && notification.parentElement) {
                notification.style.animation = 'slideOutRight 0.3s ease';
                setTimeout(() => {
                    if (notification.parentElement) {
                        notification.parentElement.removeChild(notification);
                    }
                }, 300);
            }
        }

        // 清理所有通知
        function clearAllNotifications() {
            const container = document.getElementById('notificationContainer');
            container.innerHTML = '';
        }

        // 处理扫描数据
        function processScannedData(data) {
            if (currentFocusElement.id === 'institutionCode') {
                // 机构代码处理
                const unitName = getUnitNameByCode(data);
                if (unitName !== "未知单位") {
                    document.getElementById('sendingInstitution').value = unitName;
                    // 更新显示元素
                    document.getElementById('sendingInstitutionDisplay').textContent = unitName;
                    document.getElementById('institutionCodeDisplay').textContent = data;
                    showNotification({
                        title: '机构信息',
                        message: `已自动填充机构名称: ${unitName}`,
                        type: 'success'
                    });
                } else {
                    showNotification({
                        title: '未知机构',
                        message: '未找到对应的机构信息',
                        type: 'error'
                    });
                }
            }
            
            // 处理表格中的机构代号
            if (currentFocusElement.classList.contains('table-input') && 
                currentFocusElement.placeholder.includes('机构代号')) {
                const unitName = getUnitNameByCode(data);
                if (unitName !== "未知单位") {
                    showNotification({
                        title: '机构信息',
                        message: `机构代号 ${data} 对应: ${unitName}`,
                        type: 'info'
                    });
                } else {
                    showNotification({
                        title: '未知机构',
                        message: `未找到机构代号 ${data} 对应的机构信息`,
                        type: 'error'
                    });
                }
            }
        }

        // 更新显示元素
        function updateDisplayElements() {
            const sendingInstitution = document.getElementById('sendingInstitution');
            const institutionCode = document.getElementById('institutionCode');
            const sampleSource = document.getElementById('sampleSource');
            const combinationNumber = document.getElementById('combinationNumber');
            const testDate = document.getElementById('testDate');

            if (sendingInstitution) {
                sendingInstitution.addEventListener('input', function() {
                    document.getElementById('sendingInstitutionDisplay').textContent = this.value;
                });
            }

            if (institutionCode) {
                institutionCode.addEventListener('input', function() {
                    document.getElementById('institutionCodeDisplay').textContent = this.value;
                });
            }

            if (sampleSource) {
                sampleSource.addEventListener('input', function() {
                    document.getElementById('sampleSourceDisplay').textContent = this.value;
                });
            }

            if (combinationNumber) {
                combinationNumber.addEventListener('input', function() {
                    document.getElementById('combinationNumberDisplay').textContent = this.value;
                });
            }

            if (testDate) {
                testDate.addEventListener('change', function() {
                    const date = new Date(this.value);
                    const formattedDate = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
                    document.getElementById('testDateDisplay').textContent = formattedDate;
                });
            }
        }

        // 条形码扫描功能
        function scanBarcode(targetElementId) {
            const targetElement = document.getElementById(targetElementId);
            if (targetElement) {
                targetElement.focus(); // 确保元素获得焦点
                targetElement.select(); // 选择文本
                // 模拟扫描枪输入
                const simulatedInput = new Event('input', { bubbles: true });
                targetElement.dispatchEvent(simulatedInput);
                showNotification({
                    title: '扫描成功',
                    message: `已自动填充 ${targetElementId}`,
                    type: 'success'
                });
            } else {
                showNotification({
                    title: '错误',
                    message: `未找到元素: ${targetElementId}`,
                    type: 'error'
                });
            }
        }

        // 自动填充当前日期
        window.onload = function() {
            const today = new Date();
            document.getElementById('testDate').value = today.toISOString().split('T')[0];
            updateDisplayElements();
            console.log('页面加载完成，所有字段都支持扫描枪输入');
        };
    </script>
</body>
</html> 